#include "Framework/ScriptParser/ScriptInterface.h"


#include "Framework/StableHeaders.h"


namespace tyro
{
	namespace Framework
	{

		ParamDictionaryMap ScriptInterface::dictionaryMap;

		const ParameterList& ScriptInterface::GetParameters( void ) const
		{
			static ParameterList emptyList;

			const ParameterDictionary* dict = GetParameterDictionary();
			if (dict)
				return dict->GetParameterList();
			else
				return emptyList;
		}

		void ScriptInterface::CleanupDictionary()
		{
			dictionaryMap.clear();
		}	

		bool ScriptInterface::SetParameter( const String& name, const String& value )
		{
			// Get the dictionary
			ParameterDictionary* dict = GetParameterDictionary();

			if (dict)
			{
				// Retrieve the command
				ParameterCommand* cmd = dict->GetParameterCommand(name);
				if (cmd)
				{
					cmd->Set(this, value);
					return this;
				}
			}

			// Default
			return false;
		}

		void ScriptInterface::SetParameterList( const NameValuePairList& paramList )
		{
			NameValuePairList::const_iterator i, iend;
			iend = paramList.end();
			for (i = paramList.begin(); i != iend; ++i)
			{
				SetParameter(i->first, i->second);
			}
		}

	}
}